/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.dao;
import java.sql.Connection;
import java.util.ArrayList;
import controller.vo.pruebaVO;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
 *
 * @author Fany
 */
public class pruebaDAO {
    private Connection Connex;

public ArrayList getAll(){
    ArrayList al= null;
    return al;   
  }    

public ArrayList GetElements(){
        ArrayList aListData = new ArrayList();
        String sStringSQL = "SELECT * FROM Prueba";
        PreparedStatement sPrepared_Statement= null;
        ResultSet sResult_Set = null;       
        
        try{
            Connex = Connect.getConnection(); //obtenemos la conexion a la base de datos
            sPrepared_Statement = Connex.prepareStatement(sStringSQL);
            sResult_Set = sPrepared_Statement.executeQuery();
            while( sResult_Set.next() ){
                pruebaVO Tmp_VO = new pruebaVO();
                if( sResult_Set.getString(1) != null ){
                    Tmp_VO.setNombre(sResult_Set.getString(1).trim());
                }
                
                if( sResult_Set.getString(2) != null ){
                    Tmp_VO.setEdad(Integer.parseInt( sResult_Set.getString(2).trim()) );
                }                              
                aListData.add( Tmp_VO );        
            }
         } catch ( SQLException SQL_exception ){
                System.out.println("Error al ejecutar la query --->> [ " + SQL_exception.getMessage() + " ]");
         }
        
        return aListData;
}

	public void alta(pruebaVO pvo) throws SQLException{
		// Funcion que dara de alta un registro dentro de la tabla,
		Connex = Connect.getConnection(); //obtenemos la conexion a la base de datos
                String sStringSQL = "INSERT INTO PRUEBA ( NOMBRE, EDAD ) VALUES(?,?)";
                PreparedStatement psmt= null;
            	
		try{
			psmt = Connex.prepareStatement(sStringSQL);
			psmt.setString(1,pvo.getNombre());
			psmt.setInt(2,pvo.getEdad());
			psmt.executeUpdate();
		}catch(SQLException sqle){
			throw sqle;
		}finally{
			if(psmt != null)psmt.close();
			if(Connex != null)Connex.close();
		}
	}
	
}



